package com.googlecode.afdbaccess.web.portal.exceptionmappers;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.jboss.resteasy.spi.UnauthorizedException;

import com.googlecode.afdbaccess.web.common.exception.GuiLayerUnauthorizedException;

@Provider
public class UnauthorizedExceptionMapper implements ExceptionMapper<UnauthorizedException>
{
    @Override
    public Response toResponse(UnauthorizedException exception) {
        String reason = "Not logged in, or wrong role.";
        GuiLayerUnauthorizedException guiLayerException = new GuiLayerUnauthorizedException(reason, exception);
        throw new RuntimeException(reason, guiLayerException);
    }
}
